package company.alibaba;

import java.util.Scanner;

public class Ai2 {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[][] map = new int[n][m];
        int startX = 0, startY = 0, endX = 0, endY = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                String next = scanner.next();
                if (next.equals("."))
                    map[i][j] = 1;
                else if (next.equals("#"))
                    map[i][j] = -1;
                else if (next.equals("S")){
                    map[i][j] = 2;
                    startX = i;
                    startY = j;
                }else {
                    map[i][j] = 3;
                    endX = i;
                    endY = j;
                }
            }
        }



    }
}
